import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-08
 * Time: 20:28
 */
public class Test40 {
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static TreeNode build(String str) {
        if(str == null || str.length() == 0) {
            return null;
        }
        // 替换
        String input = str.replace("[","");
        input = input.replace("]","");
        String[] part = input.split(",");
        Integer[] num = new Integer[part.length];

        for(int i = 0; i < part.length; i++) {
            if(!part[i].equals("null")) {
                num[i] = Integer.parseInt(part[i]);
            }else {
                num[i] = null;
            }
        }
        Queue<TreeNode> q = new LinkedList<>();
        TreeNode root = new TreeNode(num[0]);
        q.offer(root);
        int index = 1;

        while(!q.isEmpty() && index < part.length) {
            TreeNode node = q.poll();
            if(index < part.length && num[index] != null) {
                node.left = new TreeNode(num[index]);
                q.offer(node.left);
            }
            index++;
            if(index < part.length && num[index] != null) {
                node.right = new TreeNode(num[index]);
                q.offer(node.right);
            }
            index++;
        }
        return root;
    }



    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        TreeNode root = build(str);
        int result = diameterOfBinaryTree(root);
        System.out.println(result);
    }

    public static int diameterOfBinaryTree(TreeNode root) {
        maxDepth(root);
        return ret;
    }

    static int ret = 0;

    public static int maxDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        ret = Math.max(ret,left+right);
        return left > right?left+1:right+1;
    }
}
